/*
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2, or (at your option)
 * any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
 * 02111-1307, USA.
 *
 * http://www.gnu.org/copyleft/gpl.html
 */

package l1j.server.server.serverpackets;

import l1j.server.server.datatables.ItemTable;
import l1j.server.server.model.Instance.L1ItemInstance;
import l1j.server.server.templates.L1Item;

// Referenced classes of package l1j.server.server.serverpackets:
// ServerBasePacket

public class S_TradeAddItem extends ServerBasePacket {
	private static final String S_TRADE_ADD_ITEM = "[S] S_TradeAddItem";

	public S_TradeAddItem(final L1ItemInstance item, final long count,
			final int type) {
		this.writeC(S_OPCODE_TRADEADDITEM);
		this.writeC(type); // 0:トレードウィンドウ上段 1:トレードウィンドウ下段
		this.writeH(item.getItem().getGfxId());
		this.writeS(item.getNumberedViewName(count));
		// 0:祝福 1:通常 2:呪い 3:未鑑定
		// 128:祝福&封印 129:&封印 130:呪い&封印 131:未鑑定&封印
		this.writeC(item.getBless());
		final L1Item template = ItemTable.getInstance().getTemplate(
				item.getItemId());
		/*
		 * writeH(item.get_gfxid());//TODO 圖示 writeC(item.getBless());//TODO
		 * 祝福狀態(是否祝福 0=祝福 1=普通 2=詛咒) writeD(item.getCount());
		 * writeC((item.isIdentified()) ? 1 : 0); writeS(item.getViewName());
		 */
		if (template == null) {
			this.writeC(0x00);

		} else {
			// dummy.setItem(template);
			final byte[] status = item.getStatusBytes();
			this.writeC(status.length);
			for (final byte b : status) {
				this.writeC(b);
			}

		}
	}

	@Override
	public byte[] getContent() {
		return this.getBytes();
	}

	@Override
	public String getType() {
		return S_TRADE_ADD_ITEM;
	}
}
